<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ page import="kau.vo.*"%>
<%@ page import="kau.dao.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.net.URLEncoder"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<style type="text/css">
#relpyDiv td {
	color: blakc;
	font-family: 'Trebuchet MS', Arial, Helvetica, sans-serif;
}
</style>


<%
	Writing writing = (Writing) request.getAttribute("writing");
%>





<script type="text/javascript">
	function modifyReply(divId) {

		var rView = document.getElementById('replyView_' + divId);
		rView.style.display = "none";
		var mView = document.getElementById('replyModify_' + divId);
		mView.style.display = "block";
	}

	function rUpdate(rNumber) {

		var contents = document.getElementById('textarea_' + rNumber).value;
		if (contents == '') {
			alert("답변을 입력하세요");
			return;
		}
		$("#updateReply_" + rNumber).submit();
	}
</script>
<style type="text/css">
#view_css {
	font-family: 맑은 고딕;
	font-size: 12px
}

#reply_css {
	font-family: 맑은 고딕;
	font-size: 11px;
}

#container {
	float: right;
	margin-right: 28px;
}
</style>
</head>
<body>

	<div style="margin-top: 40px"></div>
	<table id="view_css" width="700" cellspacing="0"
		style="border: 1px solid #d6d6d6">
		<tr height="30">
			<td width="25%"
				style="border-bottom: 1px solid #d6d6d6; font-weight: bold"
				align="center" bgcolor="#e6efec">제목</td>
			<td align="left"
				style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6">
				&nbsp;&nbsp;${requestScope.writing.title}</td>
		</tr>
		<tr height="30">
			<td width="25%"
				style="border-bottom: 1px solid #d6d6d6; font-weight: bold"
				align="center" bgcolor="#e6efec">작성자</td>
			<td align="left"
				style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6">
				&nbsp;&nbsp;${requestScope.writing.writer}</td>

		</tr>
		<tr height="30">
			<td width="25%"
				style="border-bottom: 1px solid #d6d6d6; font-weight: bold"
				align="center" bgcolor="#e6efec">날짜</td>
			<td align="left"
				style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6">
				&nbsp;&nbsp;${requestScope.writing.writeTime}</td>
		</tr>
		<tr height="30">
			<td width="25%"
				style="border-bottom: 1px solid #d6d6d6; font-weight: bold"
				align="center" bgcolor="#e6efec">파일첨부</td>
			<td align="left"
				style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6">
				&nbsp;<c:if test="${not empty requestScope.fileName}">
					<a
						href="/nems/writing/fileDown.jsp?filePath=${requestScope.writing.filePath}"
						style="text-decoration: none;">${requestScope.fileName}</a>
				</c:if>
			</td>
		</tr>
		<tr height="300px">
			<td colspan="2" align="left" valign="top">${requestScope.writing.content}</td>
		</tr>

	</table>

	<table id="view_css" width="700" cellspacing="0">
		<tr>
			<td align="center" style="border-top: 1px solid #d6d6d6;"><c:if
					test="${sessionScope.custId == requestScope.writing.custId}">
					<a
						href="./updateView.writing?wNumber=${requestScope.writing.wNumber}&bNumber=${requestScope.bNumber}&courseId=${param.courseId}"
						style="text-decoration: none;"> <img alt=""
						src="/nems/writing/img/modifyBt.gif" border="0">
					</a>&nbsp;&nbsp;
				</c:if> <c:if
					test="${sessionScope.level==1 || sessionScope.custId == requestScope.writing.custId}">
					<a
						href="./deleteWriting.writing?wNumber=${requestScope.writing.wNumber}&bNumber=${requestScope.bNumber}&courseId=${param.courseId}"
						style="text-decoration: none;"><img alt=""
						src="/nems/writing/img/deleteBt.gif" border="0"> </a>&nbsp;&nbsp; 
				</c:if> <a
				href="./list.writing?bNumber=${requestScope.bNumber}&courseId=${param.courseId}"
				style="text-decoration: none;"><img alt=""
					src="/nems/writing/img/listBt.gif" border="0"></a>&nbsp;&nbsp;</td>

		</tr>

	</table>




	<div id="container">

		<div id="reply_css" align="center">

			<c:if test="${ fn:length(replyList)!=0}">

				<c:forEach items="${requestScope.replyList}" var="reply"
					varStatus="status">
					<div style="margin-top: 5px"></div>

					<form id='updateReply_${reply.rNumber}' method="post"
						action="rUpdate.writing?rNumber=${reply.rNumber}&wNumber=${requestScope.writing.wNumber}&bNumber=${requestScope.bNumber}&courseId=${param.courseId}">

						<c:if test="${sessionScope.custId == reply.custId}">

							<div id="replyView_${reply.rNumber}">
								<table width="700" cellspacing="0"
									style="border-top: 1px solid #d6d6d6">
									<tr>
										<td width="20%" height="30px"
											style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6">
											${reply.writer}</td>
										<td width="70%" rowspan="2" align="left"
											style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6">
											&nbsp;${reply.content}</td>
										<td width="10%" align="center"
											style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6; border-right: 1px solid #d6d6d6">
											<a href="javaScript:modifyReply('${reply.rNumber}')"> <img
												alt="" src="/nems/writing/img/modifyBt.gif" border="0">
										</a>
										</td>
									</tr>
									<tr>
										<td
											style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6">
											${reply.writeTime}</td>
										<td align="center"
											style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6; border-right: 1px solid #d6d6d6">
											<a
											href="./rDelete.writing?rNumber=${reply.rNumber}&wNumber=${requestScope.writing.wNumber}&bNumber=${requestScope.bNumber}&courseId=${param.courseId} ">
												<img alt="" src="/nems/writing/img/deleteBt.gif" border="0">
										</a>
										</td>
									</tr>
								</table>
							</div>


							<div id="replyModify_${reply.rNumber}" style="display: none;">
								<table width="700" cellspacing="0"
									style="border-top: 1px solid #d6d6d6">
									<tr>
										<td width="20%" height="30px"
											style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6">
											${reply.writer}</td>
										<td width="70%" rowspan="2"
											style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6">
											<textarea rows="3" id='textarea_${reply.rNumber}'
												name="rContent"
												style="width: 90%; overflow: hidden; border: 0">${reply.content}</textarea>
										</td>
										<td width="10%" rowspan="2" align="center"
											style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6; border-right: 1px solid #d6d6d6">
											<a href="javaScript:rUpdate('${reply.rNumber}')"> <img
												alt="" src="/nems/writing/img/modifyBt.gif" border="0">
										</a>
										</td>
									</tr>
									<tr>
										<td
											style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6">
											${reply.writeTime}</td>

									</tr>
								</table>
							</div>
						</c:if>

						<c:if test="${sessionScope.custId != reply.custId}">
							<table width="700" cellspacing="0"
								style="border-top: 1px solid #d6d6d6">
								<tr>
									<td width="20%" height="30px"
										style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6">
										${reply.writer}</td>
									<td width="80%" rowspan="2"
										style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6 ;border-right: 1px solid #d6d6d6">
										${reply.content}</td>

								</tr>
								<tr>
									<td
										style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6 ; ">
										${reply.writeTime}</td>
								</tr>
							</table>


						</c:if>

					</form>
				</c:forEach>
			</c:if>

			<c:if test="${not empty sessionScope.custId}">
				<div style="margin-top: 5px"></div>
				<form id="replyForm"
					action="rWrite.writing?wNumber=${requestScope.writing.wNumber}&bNumber=${requestScope.bNumber}&courseId=${param.courseId}"
					method="post">

					<table width="700" cellspacing="0"
						style="border-top: 1px solid #d6d6d6">
						<tr height="30">
							<td width="20%" height="50px"
								style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6">
								${sessionScope.custName}</td>
							<td width="70%" rowspan="2"
								style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6; border-right: 1px solid #d6d6d6">
								<textarea rows="3" id='textarea_${reply.rNumber}'
									name="rContent"
									style="width: 100%; overflow: hidden; border: 0; font-size: 10px; font-family: 맑은 고딕;">답변을 적으세요</textarea>
							</td>
							<td width="10%"
								style="border-bottom: 1px solid #d6d6d6; border-left: 1px solid #d6d6d6; border-right: 1px solid #d6d6d6"
								align="center"><img src="/nems/writing/img/replyBt.gif"
								onclick="javascript:submit()"></td>
					</table>


				</form>
		</div>

		</c:if>

	</div>

	<div style="margin-bottom: 30px"></div>


</body>
</html>